-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Interaction
, and replace it with bevy_picking
based fields on Button
#15597
base: main
Are you sure you want to change the base?
Conversation
Interaction
, and replace it with a bevy_picking
based alternativeInteraction
, and replace it with bevy_picking
based fields on Button
From game maker perspective- how to most easily get the "is this button just released" info? |
I think that the best strategy is to use an observer listening to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea in general,
not super sure about the separation (button has pressed & hovered) / naming (button) here.
There can be label widgets that get highlighted when hovered over, does that make them a button?
If not, should hovered be a separate component or should button have a better name
The idea from @NthTensor is that each widget type should track its own interaction state independently, as its rules may differ. I agree with this design. I would have showcased it here, but uh, we only have one widget type 😅 |
The generated |
pickable: Pickable { | ||
should_block_lower: true, | ||
..Default::default() | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pickable: Pickable { | |
should_block_lower: true, | |
..Default::default() | |
}, | |
pickable: Pickable::default(), |
should_block_lower
is true
by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great; that means we can swap to a pure derive then.
|
let mut hovering_over_descendant = false; | ||
|
||
for descendant in children_query.iter_descendants(entity) { | ||
if map.contains_key(&descendant) { | ||
hovering_over_descendant = true; | ||
break; | ||
} | ||
} | ||
hovering_over_descendant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it possible to use any()
with DescendantsIter
?
Objective
Fixes #15550. See that issue and the linked issues within it about why the existing
Interaction
component is inadequate.Solution
Interaction
and all engine systems that use itpressed
andhovered
fields toButton
bevy_picking
button
examplemake Text entities not pickable by defaultFocusPolicy
in favor ofPickable
RelativeCursorPosition
. Widgets should compute this information themselves based onbevy_picking
input.animation_graph
exampleNote to reviewers: the previous solution has special-cased logic for hidden nodes to ensure that they can't be pressed. I would prefer not to implement that in this PR, as that's fundamentally a picking backend concern.
Testing
For basic functionality, run the
button
example.For something more holistic, try the
game_menu
example.Migration Guide
The
Interaction
component has been removed. Instead, use the newpressed
andhovered
fields onButton
. Bear in mind that you can also use observers to listen forbevy_picking
events such asPointer<Down>
andPointer<Over>
directly as well.To migrate code that matches on
Interaction
to change some property, follow the example below:Bevy 0.14:
Bevy 0.15:
NodeBundle
(and their Bevy 0.15 equivalents) no longer track whether or not they are pressed / hovered by default. If you require this functionality, add theButton
component to your entity.The
FocusPolicy
component has been removed, and replaced with the universalPickable
component.The
RelativeCursorPosition
component has been removed. If you need this information, you should compute it frombevy_picking
events in your widget's logic. See theanimation_graph
example for a demonstration of how this can be done.